import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
    server: {
        proxy: {
            // 字符串简写写法：
            // http://localhost:5173/foo
            // -> http://localhost:4567/foo
            // '/foo': 'http://localhost:4567',
            // 带选项写法：
            // http://localhost:5173/api/bar
            // -> http://jsonplaceholder.typicode.com/bar
            '/api': {
                target: 'http://localhost:6000',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ''),
            },
        }}
})
